package zz.app.jmhviewer;

import android.app.Dialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;
import android.support.annotation.RequiresApi;

import java.io.IOException;

import zz.app.jmhviewer.JMH.JMHUtils;

/**
 * Created by zz on 2018/1/31 21:47.
 */

public class GetMusicTask extends AsyncTask<String,Integer,Integer>{
    private Context context;
    private String musicPath;
    private Dialog dialog;
    private OnFinishedListener listener;
    public GetMusicTask(Context c, OnFinishedListener l){
        context=c;
        listener=l;
    }

    public String getMusicPath() {
        return musicPath;
    }

    @Override
    protected Integer doInBackground(String... strings) {
        try {
            String host=strings[0];
            String name=strings[1];
            musicPath=JMHUtils.getMusicData(host,name,null);
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        } catch (IOException e) {
            e.printStackTrace();
            return -1;
        }
        return 0;
    }



    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }

    @Override
    protected void onPostExecute(Integer o) {
        super.onPostExecute(o);
        if(listener!=null){
            listener.onFinish();
        }

    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }
}
